//获取应用实例
var app = getApp()
var start=0;
const API_URL = 'https://api.douban.com/v2/movie/top250'

Page({
  data: {
    loadingHide:false,
    title:"加载中...",
    movies:[]
  },
  onLoad: function () {
    var that = this;
    wx.request({
      url: API_URL+'?start='+start, 
      data: {},
      method: 'GET', 
      header: {
          'content-type':'json'
      },
      success: function(res) {
        console.log(res.data)
        var data = res.data;
        that.setData({
          title:data.title,
          loadingHide: true,
          movies:data.subjects
        });
      }
    })
  },
  lower:function(e){
    var that = this;
    start=start+20;
    if(start>=260){
      return ;
    }
    that.setData({
      loadingHide:false
    })
    wx.request({
      url: API_URL+'?start='+start, 
      data: {},
      method: 'GET', 
      header: {
          'content-type':'json'
      },
      success: function(res) {
        console.log(res.data)
        var data = res.data;
        that.setData({
          loadingHide: true,
          movies:that.data.movies.concat(data.subjects)
        });
      }
    })
  }
})
